# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# Name:         config.py
# Purpose:      The main frame
#
# Author:       Zhang Kun
#
# Created:      2/22/08
# Copyright:    (c) 2007-2008 HanMingSoft, Inc.
# License:      Apache License v2.0
#----------------------------------------------------------------------------

from data import Customer
from report import Report, A4L
from reportlab.pdfgen import canvas
from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib import colors

class CustomerList(Report):
    def __init__(self, datas):
        Report.__init__(self, size=A4L, title="My title")
        self.datas = datas

    def Draw(self):
        head = [[u"客户名称", u"电话", u"传真", u"联系人", u"联系人电话", \
        u"国家", u"邮编", u"省(直辖市)", u"市（县区）", u"详细地址", u"开户银行", u"银行帐号", u"税号"]]

        lst = []
        lst.append(Paragraph(u"<para align=center spaceb=0 spacea=10><font name='simhei'>客户一览表<font></para>", self.style['Heading1']))
        style = self.GetStyle()
        t = Table(head + self.datas,repeatRows=1)
        t.setStyle(style)
        lst.append(t)

        self.doc.build(lst)

    def GetStyle(self):
        return(TableStyle([('FONT', (0,0), (-1,0), 'simhei'), \
                           ('FONTSIZE', (0,0), (-1,0), 11), \
                           ('ALIGN', (0,0), (-1,0), 'CENTER'), \
                           ('LINEBELOW', (0,0), (-1,0), 0.75, colors.black), \
                           ('FONT', (0,1), (-1,-1), 'simsun'), \
                           ('FONTSIZE', (0, 1), (-1,-1), 10), \
                           ('BOX', (0,0), (-1,-1), 0.75, colors.black),
                           ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                           ]))

if __name__ == '__main__':
    import wx
    app = wx.PySimpleApp()
    datas = Customer().GetAll(['name', 'tel', 'fax', 'linkman', 'linkman_tel', \
        'country', 'zip', 'address1', 'address2', 'address3', 'bank', 'account', 'tax_num'])
    rpt = CustomerList(datas)
    rpt.Draw()
    rpt.Preview()
    app.MainLoop()